﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq.Expressions;
using EFCTP.Entity;

namespace EFCTP.DBContext
{
    public class IndustryContext : DbContext
    {
        public DbSet<Industry> Industries { set; get; }
        public DbSet<Product> Products { set; get; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            //Database.SetInitializer<IndustryContext>(new DropCreateDatabaseAlways<IndustryContext>());
            modelBuilder.Conventions.Remove<IncludeMetadataConvention>();
            modelBuilder.Entity<Industry>().Property(d => d.ParentCode).IsOptional();
        }

        public IndustryContext()
            : base()
        { }

        public IndustryContext(string strConn)
            : base(strConn)
        {
            
        }

        public static IndustryContext db = DBSample.dbcontext;

        class DBSample
        {
            static DBSample() { }
            public static readonly IndustryContext dbcontext = new IndustryContext("EFCTP");
        }
    }
}

